<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>文章列表</title>
    <link type="text/css" rel="stylesheet" href="<?php echo base_url() ?>public/css/style.css" />
</head>

<body>
<div class="wrapper">
	<p class="p-new"><a href="<?php echo base_url() ?>article/add.html" class="a-add">新增</a> 
	<!-- 根据显示方式的不同,提供不同的按钮 -->
	<?php if($links): ?><a href="<?php echo base_url() ?>article/" class="a-kinds">显示全部</a>
	<?php else:?><a href="<?php echo base_url() ?>article/articleList.html" class="a-kinds">分页显示</a>
	<?php endif; ?> </p>

	<ul class="ul-list">
		<!-- 遍历数组输出文章记录信息 -->
		<?php foreach ($article as $v): ?>
		<li class="li-list">
			<a href="<?php echo base_url() ?>article/detail/<?php echo $v['aid'] ?>.html" class="a-title" target="_blank"><span class="s-title"><?php echo $v['title'] ?></span></a>
			<span class="s-time"><?php echo date('Y-m-d H:i:s',$v['time']) ?></span>
			<span class="s-op"><a href="<?php echo base_url() ?>article/edit/<?php echo $v['aid'] ?>.html" target="_blank">编辑</a>
			<a href="<?php echo base_url() ?>article/delete/<?php echo $v['aid'] ?>.html" class="a-del">删除</a></span>
			<!-- 显示文章内容的前50个字 -->
			<div class="content-b"><?php echo cutstr_html($v['content'],50) ?></div>
		</li>
		<?php endforeach;?>
	</ul>

	<!-- 根据变量的设置情况显示分页按钮-->
	<?php if($links): ?>
		<?php echo $links ?>
	<?php endif; ?>

</div>
<script type="text/javascript" src="<?php echo base_url() ?>public/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>public/js/base.js"></script>
<script type="text/javascript">

$.ajax({
	url:'/article/json',
	type : 'get',
	success : function (data) {
		window.console && console.log(data);
		var data = eval('('+data+')');
		window.console && console.log(data);
	}
});
/*使用ajax请求删除文章,并根据结果做出提示*/
$('.a-del').click(function() {
	var _self = $(this);
	$.sobox.confirm('删除提示','你确定删除此信息吗？',function () {
		var url = _self.attr('href');
		$.getJSON(url,function (data) {
			window.console && console.log(data);
			if (data.state) {
				$.sobox.alert('提示','删除成功！');
			};
		});
	})
	return false;
});
</script>
</body>
</html>